#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct brand
{
    char name[10];
    int num;
}brand;
void Swap1(brand arr[15])
{
    int i = 0;
    int j = 0;
    int m = 0;
    for (i; i < 14; i++)
    {
        for (j = 0; j < 14 - i; j++)
        {
            if (arr[j].num > arr[j + 1].num)
            {
                int tmp = arr[j].num;
                char tmp2[10] = { 0 };
                for (m = 0; m < 10; m++)
                {
                    tmp2[m] = arr[j].name[m];
                }
                arr[j].num = arr[j + 1].num;
                arr[j + 1].num = tmp;
                for (m = 0; m < 10; m++)
                {
                    arr[j].name[m] = arr[j + 1].name[m];
                }
                for (m = 0; m < 10; m++)
                {
                    arr[j + 1].name[m] = tmp2[m];
                }
            }
        }
    }
}
void Swap(brand arr[])
{
    int i = 0;
    int j = 0;
    int m = 0;
    for (i; i < 14; i++)
    {
        for (j = 0; j < 14 - i; j++)
        {
            if (arr[j].name[0] > arr[j + 1].name[0])
            {
                int tmp = arr[j].num;
                char tmp2[10] = { 0 };
                for (m = 0; m < 10; m++)
                {
                    tmp2[m] = arr[j].name[m];
                }
                arr[j].num = arr[j + 1].num;
                arr[j+1].num = tmp;
                for ( m = 0; m < 10;m++)
                {
                    arr[j].name[m] = arr[j + 1].name[m];
                }
                for ( m = 0; m < 10; m++)
                {
                    arr[j+1].name[m] =tmp2[m];
                }
            }
        }
    }
}
int main()
{
    int n = 0;
    scanf("%d", &n);
    brand arr[15];
    int i = 0;
    for (i; i < 15; i++)
    {
        scanf("%s", arr[i].name);
        scanf("%d", &arr[i].num);
    }
    Swap1(arr);
    Swap(arr);
    for (i=0; i < 15; i++)
    {
        printf("%s", arr[i].name);
        printf(" %d", arr[i].num);
        printf("\n");
    }
}